/**
 * Created by zhouli on 18/9/8
 * Email li.zhou@huilianyi.com
 */
import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';
import valueListService from 'containers/setting/value-list/value-list.service';
export default {
  //新增值列表项：仅仅自定义值列表项
  createValueListItem: function (params) {
    return new Promise(function (resolve, reject) {
      valueListService.newValue(params)
        .then(function (res) {
          resolve(res);
        })
        .catch(function (err) {
          reject(err.response);
        })
    })
  },
  //编辑值列表项：仅仅自定义值列表项
  updateValueListItem: function (params) {
    return new Promise(function (resolve, reject) {
      valueListService.updateValue(params)
        .then(function (res) {
          resolve(res);
        })
        .catch(function (err) {
          reject(err.response);
        })
    })
  },
  //查询值列表项：仅仅自定义值列表项
  getDetailValueListItem: function (customEnumerationItemOID) {
    return new Promise(function (resolve, reject) {
      valueListService.getValue(customEnumerationItemOID)
        .then(function (res) {
          resolve(res);
        })
        .catch(function (err) {
          reject(err.response);
        })
    })
  },
  //查询值列表项人员：带关键字查询
  getPersonValueListItem: function (params) {
    // let params = {
    //   page,
    //   size,
    //   keyword,
    //   customEnumerationItemOID:OID
    // }
    return new Promise(function (resolve, reject) {
      httpFetch.get(config.baseUrl + '/api/custom/enumerations/items/users', params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
  //查询值列表项部门：带关键字查询
  getDepValueListItem: function (params,customEnumerationItemId) {
    // let params = {
    //   page,
    //   size,
    //   keyword,
    //   customEnumerationItemOID:OID
    // }
    return new Promise(function (resolve, reject) {
      httpFetch.get(config.baseUrl + '/api/custom/enumerations/items/department/'+customEnumerationItemId, params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
  //关联值列表项部门与人员
  addPersonOrDepValueListItem: function (params) {
    return new Promise(function (resolve, reject) {
      httpFetch.post(config.baseUrl + '/api/custom/enumerations/items/users', params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },

  //删除值列表项部门
  delDepValueListItem: function (id) {
    return new Promise(function (resolve, reject) {
      httpFetch.delete(config.baseUrl + '/api/custom/enumerations/items/department/'+id)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
  //删除值列表项人员
  delPersonValueListItem: function (params) {
    return new Promise(function (resolve, reject) {
      httpFetch.delete(config.baseUrl + '/api/custom/enumerations/items/users', params)
        .then(function (res) {
          resolve(res)
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },

}
